﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
public partial class Manage_CompanSearch_DonotSpeak : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            string strtemp, delInfoId;
            if (Request.Form["btnSubmit"] == "添　加" && Request.Form["chk"] != null)
            {
                delInfoId = Request.Form["chk"].ToString();
                strtemp = "insert into CompanyDonotSpeak (accountid ,UserCode,CompanyName,addtime,memo1) select accountid,UserCode,CompanyName,getdate(),'' from v_company where accountid in (" + delInfoId + ")";
                Db db = new Db();
                int ii = db.Command(strtemp);
                db.Close();
                if (ii >= 1)
                {
                    Response.Write("<script>alert('添加成功！');</script>");
                }

            }
            showGridView();
        }
    }
    /// <summary>
    /// 数据绑定
    /// </summary>
    public void showGridView()
    {
        string strConditions;
        strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "v_company";                                               //要查询的表明
        dbPage.Key = "AccountId";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "AccountId,UserCode,CompanyName";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 30;                                                    //没有显示记录条数   
        dbPage.OrderBy = "CompanyName";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        DlAttorney.DataSource = dr;
        DlAttorney.DataBind();
        dr.Close();
        dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键
    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = "", CompanyName = "", UserCode;
        UserCode = txtUserCode.Text.Trim();
        CompanyName = txtAttorneyName.Text.Trim();
        strtemp = "  accountid not in(select accountid from CompanyDonotSpeak ) And";
        if (UserCode != "")
        {
            strtemp = strtemp + " UserCode like '%" + UserCode + "%' and";
        }
        if (CompanyName != "")
        {
            strtemp = strtemp + " CompanyName like '%" + CompanyName + "%' and";
        }
        if (strtemp != "")
        {
            strtemp = "  " + strtemp.Substring(0, strtemp.Length - 3);
        }
        return strtemp;

    }
}
